﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private List<Image> lst = new List<Image>();
        private int ImageIndex = 0;
        private Timer timer2 = new Timer();
        public Form1()
        {
            InitializeComponent();
            //获取当前工作区宽度和高度（工作区不包含状态栏）
            //int ScreenWidth = Screen.PrimaryScreen.WorkingArea.Width;
            ////int ScreenHeight = Screen.PrimaryScreen.WorkingArea.Height;
            ////// //计算窗体显示的坐标值，可以根据需要微调几个像素
            //int x = ScreenWidth ;
            //int y = ScreenHeight + 1;
            Helper();

        }
        // string sql = "select CARD_NAME from T_CARDINFO where CARD_STAUTS = '2' and CARD_PRINTSTAUTS = '3'";

        private void Helper()
        {
            //添加广告照片 1600*900
            string filename = System.Windows.Forms.Application.StartupPath + "\\Resources";
            DirectoryInfo dir = new DirectoryInfo(filename);
            FileInfo[] fil = dir.GetFiles();
            foreach (FileInfo f in fil)
            {
                lst.Add(Image.FromFile(f.FullName));//添加文件路径到列表中  
            }
            timer3.Start();
        }


        private void timer2_Tick(object sender, EventArgs e)
        {
            elementHost1.Visible = false;
            //广告计时器
            //旋转90度
            //lst[ImageIndex].RotateFlip(RotateFlipType.Rotate90FlipNone);
            pictureBox1.Image = lst[ImageIndex];
            ImageIndex++;
            if (ImageIndex > lst.Count - 1) ImageIndex = 0;
            Bitmap bmp = new Bitmap(pictureBox1.Image);
            ///左右效果

            Bitmap MyBitmap = (Bitmap)bmp.Clone();
            int dh = MyBitmap.Height / 20;
            int dw = MyBitmap.Width;
            Graphics g = pictureBox1.CreateGraphics();
            g.Clear(Color.Gray);
            Point[] MyPoint = new Point[20];
            for (int y = 0; y < 20; y++)
            {
                MyPoint[y].X = 0;
                MyPoint[y].Y = y * dh;
            }
            Bitmap bitmap = new Bitmap(MyBitmap.Width, MyBitmap.Height);
            for (int i = 0; i < dh; i++)
            { 
                for (int j = 0; j < 20; j++)
                {
                    for (int k = 0; k < dw; k++)
                    {
                        bitmap.SetPixel(MyPoint[j].X + k, MyPoint[j].Y + i, MyBitmap.GetPixel(MyPoint[j].X + k, MyPoint[j].Y + i));
                    }
                }
                pictureBox1.Refresh();
                pictureBox1.Image = bitmap;
                System.Threading.Thread.Sleep(0);
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //Application.Restart();
            //打印叫号计时器

            string connectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionstring"];
            string sql = "select CARD_NAME from T_CARDINFO where CARD_STAUTS = '1' and CARD_PRINTSTAUTS = '2'";
           this.userControl111.lb.Items.Clear();
            DataSet ds = new DataSet();
            using (SqlConnection sqlcn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand(sql, sqlcn))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    sqlcn.Open();
                    adapter.SelectCommand = cmd;
                    adapter.Fill(ds, "province");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {

                        userControl111.lb.Items.Add(ds.Tables[0].Rows[i]["CARD_NAME"] + "  ");
                    }

                }
            }

           

        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            
            string sql = "select * from T_CARDINFO where  CARD_STAUTS != '2' AND CARD_PRINTSTAUTS != '1'";
            if (SQL.GetDataSet(sql).Rows.Count is 0)
            {
                timer2.Start();
                elementHost1.Visible = false;
                pictureBox1.Visible = true;

            }
            else
            {
               
                pictureBox1.Visible = false;
                elementHost1.Visible = true;
                timer2.Stop();

            }  //查询当前是否有人在办理

        }
    }
}
